#include "cilantro.h"
#include "sql.h"


struct cilantro_sql_t * cilantro_sql_init(struct cilantro_sql_t ** c) {
	
	int res = 0;
	char db_filename[256];
	struct cilantro_sql_t * t = (*c);

	t = (struct cilantro_sql_t * ) malloc( sizeof(struct cilantro_sql_t) );
	bzero( ( char * ) &t, sizeof(struct cilantro_sql_t) );

	config_init( t->cfg );
	
	if(! (config_read_file(t->cfg, CFG_NAME)))
	{
		printf("DEBUG Error reading config file\n");
		return res;
	}

	if(!config_lookup_string(t->cfg, "cilantro.sql.db",db_filename)) {
		printf("DEBUG Error cant find database file\n");
		return res;
	}
	
	if(! sqlite_open(db_filename, 0777, &t->db)) {
		printf("DEBUG Error create/opening database file\n");
		return res;
	}
	
		
	
	return t;
}



